package com.moyun.zbmy.zizhou.ui.activities;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.sdk.statisticssdk.StatisticsMainInit;
import com.gridsum.tracker.GridsumWebDissector;
import com.gridsum.videotracker.entity.VideoInfo;
import com.jiongbull.jlog.JLog;
import com.luck.picture.lib.PictureExternalPreviewActivity;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.moyun.zbmy.zizhou.application.Cache;
import com.moyun.zbmy.zizhou.beans.AccountNewsItem;
import com.moyun.zbmy.zizhou.beans.FComment;
import com.moyun.zbmy.zizhou.beans.FNews;
import com.moyun.zbmy.zizhou.beans.NewsItem;
import com.moyun.zbmy.zizhou.beans.SingleResult;
import com.moyun.zbmy.zizhou.http.ParamsEditor;
import com.moyun.zbmy.zizhou.ui.utils.SampleListener;
import com.moyun.zbmy.zizhou.ui.utils.SkipUtil;
import com.moyun.zbmy.zizhou.ui.widget.BasePlayerView;
import com.ruihang.generalibrary.ui.dialog.ShareFragment;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.application.Constances;
import com.moyun.zbmy.zizhou.base.BaseAccountActivity;
import com.moyun.zbmy.zizhou.beans.AccountBean;
import com.moyun.zbmy.zizhou.beans.AccountNewsArticleBean;
import com.moyun.zbmy.zizhou.beans.AccountNewsDetail;
import com.moyun.zbmy.zizhou.http.AbsNetCallBack;
import com.moyun.zbmy.zizhou.http.NetUtils;
import com.moyun.zbmy.zizhou.ui.utils.DataUtils;
import com.moyun.zbmy.zizhou.ui.utils.GlideCircleTransform;
import com.moyun.zbmy.zizhou.ui.utils.GlideUtil;
import com.moyun.zbmy.zizhou.utils.UserManager;
import com.ruihang.generalibrary.utils.DateUtils;
import com.ruihang.generalibrary.utils.ListUtils;
import com.ruihang.generalibrary.utils.NetModeUtil;
import com.ruihang.generalibrary.utils.SharedPreferencesUtil;
import com.ruihang.generalibrary.utils.UrlUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.RequestBody;

/**
 * 互动号文章详情（新闻有图、无图）
 */
public class AccountNewsDetailActivity extends BaseAccountActivity {
    @BindView(R.id.account_news_title)
    protected CustomFontTextView accountNewsTitle;
    @BindView(R.id.account_layout)
    protected RelativeLayout account_layout;
    @BindView(R.id.account_avatar)
    protected ImageView accountAvatar;
    @BindView(R.id.account_name)
    protected CustomFontTextView accountName;
    @BindView(R.id.news_detail_player)
    protected BasePlayerView videoPlayer;
    @BindView(R.id.account_time)
    protected CustomFontTextView accountTime;
    @BindView(R.id.account_subscribe)
    protected ImageView accountSubscribe;
    @BindView(R.id.account_news_content)
    protected WebView webView;
    @BindView(R.id.comment_layout_number)
    protected CustomFontTextView commentNumber;
    @BindView(R.id.comment_layout_doup)
    protected CustomFontTextView commentDoup;
    @BindView(R.id.comment_layout_share)
    protected CustomFontTextView shareBtn;

    private Handler handler;
    private ArrayList<Pair<String, String>> pairs;
    public static int REQUEST_COMMENT_CODE = 505;
    public static final String NEWS_BEAN = "news_bean";
    private int capacity = 5;//请求数据条数
    private int indexNumber = 0;
    private int commentCount = 0;//评论数
    private String newsUrl;
    private AccountNewsItem newsItem;
    private FNews fNews;
    private int fontSize;//字体大小
    private ArrayList<LocalMedia> imgs;
    private int fontSpacing;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler = new Handler();
        videoPlayer.setMute(true);
        fontSize = Constances.MID_FONT ;

        getDetailData();
    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_account_news_detail);
        ButterKnife.bind(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        videoPlayer.setMute(videoPlayer.isMute());
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (null != videoPlayer) {
            videoPlayer.onVideoPause();
        }
    }

    /**
     * 获取详情
     */
    private void getDetailData() {
        Serializable se = getIntent().getSerializableExtra(NEWS_BEAN);
        if (se instanceof AccountNewsItem) {
            newsItem = (AccountNewsItem) se;
            newsUrl = newsItem.getNewsDetailUrl();
            NetUtils.getNetAdapter().getNewsInfo(getOwnerName(), newsUrl, new AbsNetCallBack<FNews>(FNews.class) {

                @Override
                public void onSuc(FNews datas) {
                    if (datas != null) {
                        fNews = datas;
                        initDetailData();
                    }
                }

                @Override
                public void onError(Throwable ex, String errorMsg, int netCode) {
                    super.onError(ex, errorMsg, netCode);
                }

                @Override
                public void onEnd() {
                    super.onEnd();

                }
            });
            getCommentNews("" + newsItem.getNewsDetailId(), Constances.REQUEST_COMMENT_TYPE_NEWS, capacity, indexNumber);
        }

    }

    /**
     * 初始详情UI数据
     */
    private void initDetailData() {
        if (null != fNews) {
            if (!TextUtils.isEmpty(fNews.getShareURL())) {
                shareBtn.setVisibility(View.VISIBLE);
            }
            if (newsItem.getNewsDetailType() == 3) {
                videoPlayer.setVisibility(View.VISIBLE);
                VideoInfo videoInfo = new VideoInfo("");
                videoInfo.Cdn = "cdn";
                videoInfo.VideoOriginalName = fNews.getNewsTitle();
                videoInfo.VideoName = fNews.getNewsTitle();
                videoInfo.VideoUrl = UrlUtils.linkUrls(Constances.ST_BASE_URL, fNews.getNewsMediaUrl());
                videoInfo.extendProperty1 = "直播三台APP_Android";
                try {
                    videoInfo.extendProperty1 = "直播三台APP_Android_" + getApplicationContext().getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
                } catch (PackageManager.NameNotFoundException e) {
                    e.printStackTrace();
                }
                videoInfo.extendProperty1 = NetUtils.GetNetName(this);
                videoInfo.setVideoWebChannel("///");
                initVideoPlayer(videoPlayer, videoInfo, false);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        int netType = NetModeUtil.GetNetype(AccountNewsDetailActivity.this);
                        actionPlay(videoPlayer, UrlUtils.linkUrls(Constances.ST_BASE_URL, newsItem.getNewsDetailVideo())
                                , newsItem.getNewsDetailTitle(), newsItem.getNewsDetailSmallImage(), netType == 1);
                    }
                }, 100);
            }
            GlideUtil.getCircleGlid(this, newsItem.getFollowedSmallImage(), true).diskCacheStrategy(DiskCacheStrategy.NONE)
                    .transform(new GlideCircleTransform(this)).into(accountAvatar);
            accountName.setText(newsItem.getFollowedName());
            if (newsItem.getFollowedStatus() == 1) {
                accountSubscribe.setImageDrawable(getResources().getDrawable(R.mipmap.icon_subscribed));
            } else {
                accountSubscribe.setImageDrawable(getResources().getDrawable(R.mipmap.icon_subscribe));
            }
            account_layout.setVisibility(View.VISIBLE);
            accountNewsTitle.setText(newsItem.getNewsDetailTitle());
            accountNewsTitle.getPaint().setFakeBoldText(true);
            String timeStr = DateUtils.formatDate(DateUtils.getDataDate(newsItem), "");
            accountTime.setText(timeStr);
            if (null != newsItem) {
                if (newsItem.isNewsDetailAttitudesStatus()) {
                    Drawable drawable = AccountNewsDetailActivity.this.getResources().getDrawable(R.mipmap.icon_compere_btn_press);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                    commentDoup.setDrawables(drawable, null, null, null);
                    commentDoup.setTextColor(AccountNewsDetailActivity.this.getResources().getColor(R.color.colorTxRedMain_));
                } else {
                    Drawable drawable = AccountNewsDetailActivity.this.getResources().getDrawable(R.mipmap.icon_compere_btn_normal);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                    commentDoup.setDrawables(drawable, null, null, null);
                    commentDoup.setTextColor(AccountNewsDetailActivity.this.getResources().getColor(R.color.colorOpinionSelectNo));
                }
                commentDoup.setText("" + newsItem.getNewsDetailAttitudesCount());
            }

            String url = UrlUtils.linkUrls(Constances.ST_BASE_URL, fNews.getNewsContentH5());
            setWebs(url, true);
        }

    }

    /**
     * 首次加载web，或者修改了字体大小的时候调用
     *
     * @param url web的路径
     * @param ts  字体大小
     */
    private void resetWebView(String url, WebSettings.TextSize ts) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
        }
        initWebView(webView, ts);
        webView.loadUrl(url);
    }

    private WebSettings.TextSize getWebTextSize() {
        WebSettings.TextSize ts = null;
        if (fontSize == Constances.BIG_FONT) {
//                setFontSize(Constances.BIG_FONT);
            ts = WebSettings.TextSize.LARGEST;
            fontSpacing = Constances.SPACING_LARGE;
        } else if (fontSize == Constances.MID_FONT) {
//                setFontSize(Constances.MID_FONT);
            ts = WebSettings.TextSize.LARGER;
            fontSpacing = Constances.SPACING_MIDDLE;
        } else if (fontSize == Constances.SMALL_FONT) {
//                setFontSize(Constances.SMALL_FONT);
            ts = WebSettings.TextSize.NORMAL;
            fontSpacing = Constances.SPACING_SMALL;
        }
        return ts;
    }

    /**
     * 加载web页面
     *
     * @param url
     * @param hasChangeFont 是否改变了字体大小
     */
    private void setWebs(String url, boolean hasChangeFont) {
        JLog.e("qqa  url=" + url + "  has change " + hasChangeFont);
        if (hasChangeFont || webView == null) {
            resetWebView(url, getWebTextSize());
        } else {
            webView.loadUrl(url);
        }
    }

    @SuppressLint("JavascriptInterface")
    private void initWebView(@NonNull WebView wv, WebSettings.TextSize ts) {
        WebSettings settings = wv.getSettings();
        JLog.e("font size=" + fontSize + "   " + settings.getDefaultFontSize() + "   " + settings.getDefaultFixedFontSize());
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        settings.setJavaScriptEnabled(true);
        int dfs = settings.getDefaultFontSize();
        int dffs = settings.getDefaultFixedFontSize();
//        Message msg = new Message();
//        msg.what = fontSize;
//        fontCallback.onCallBackMsg(null, msg);
        settings.setDefaultFontSize(20);
        settings.setDefaultFixedFontSize((int) (20f * dffs / dfs));
        settings.setDefaultTextEncodingName("utf-8");
        settings.setTextSize(ts);
//        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
//        settings.setUseWideViewPort(true);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String s) {
                if (!s.startsWith("http://") && !s.startsWith("https://")) {
                    return true;
                }
                JLog.e("eese s=" + s);
                if (!TextUtils.isEmpty(s)) {
                    if (s.endsWith(".json")) {
                        toAnotherNewsDetail(s);
                    } else {
                        toH5(s);
                    }
                }
                return true;
            }

            @Override
            public void onPageFinished(WebView webVie, String s) {
                super.onPageFinished(webVie, s);
                //这个是一定要加上那个的,配合scrollView和WebView的height=wrap_content属性使用
//                int w = View.MeasureSpec.makeMeasureSpec(0,
//                        View.MeasureSpec.UNSPECIFIED);
//                int h = View.MeasureSpec.makeMeasureSpec(0,
//                        View.MeasureSpec.UNSPECIFIED);
//                //重新测量
//                JLog.e("webView: w=" + w + " h=" + h);
//                webView.measure(w, height);
//                if (height != -1) {
//                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) webView.getLayoutParams();
//                    params.height = height;
//                    webView.setLayoutParams(params);
//                }

//                webView.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        int width = webView.getWidth();
//                        if (isFirst) {
//                            height = webView.getHeight();
//                            isFirst = false;
//                        }
//                        JLog.e("webView post: w=" + width + " h=" + height);
//                    }
//                }, 500);
            }
        });

        wv.setWebChromeClient(new WebChromeClient() {
        });

        wv.addJavascriptInterface(getHtmlObject(), "jsObj");
//        wv.addJavascriptInterface();
    }

    private Object getHtmlObject() {
        Object insertObj = new Object() {
            @JavascriptInterface
            public String HtmlcallJava2(String s) {
                int pos = -1;
                if (!TextUtils.isEmpty(s) && ListUtils.isListValued(imgs)) {
                    s = UrlUtils.linkUrls(Constances.ST_BASE_URL, s);
                    for (int i = 0; i < imgs.size(); i++) {
                        if (TextUtils.equals(s, imgs.get(i).getPath())) {
                            pos = i;
                            break;
                        }
                    }
                }
                if (pos < 0) {
                    toast(R.string.data_wrong);
                } else {
                    Intent intent = new Intent(AccountNewsDetailActivity.this, PictureExternalPreviewActivity.class);
                    intent.putExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, imgs);
                    intent.putExtra(PictureConfig.EXTRA_POSITION, pos);
                    intent.putExtra("type", 2);
                    startActivity(intent);
                }
                return "java" + s;
            }

            @JavascriptInterface
            public void getContenttttHeight(int h) {
                int ch = webView.getContentHeight();
                JLog.e("eeae  h=" + h + "  ch=" + ch + "   " + webView.getHeight());
                if (ch > 0 && Math.abs(h + fontSpacing - ch) > 20) {
//                    resetWebHeght((int) ((h + fontSpacing) * webView.getScale()));
                }
//                if (Math.abs(h+Con))
            }
        };
        return insertObj;
    }

    private void toAnotherNewsDetail(String url) {
        if (!TextUtils.isEmpty(url)) {
            Intent intent = new Intent(this, NewesDetailActivity.class);
            intent.putExtra(EX_URL, url);
            startActivity(intent);
        }
    }

    private void toH5(String url) {
        if (!TextUtils.isEmpty(url)) {
            Intent intent = new Intent(this, H5NormalActivity.class);
            intent.putExtra(EX_TITLE, fNews.getNewsTitle());
            intent.putExtra(EX_HTML, url);
            startActivity(intent);
        }
    }


    /**
     * 刷新评论数据
     *
     * @param count
     */
    private void refreshBottomCommentShowing(int count) {
        String str = getString(R.string.detail_comment_no);
        if (count > 0) {
            if (count > 99) {
                str = getString(R.string.detail_comment_counts);
            } else {
                str = getString(R.string.detail_comment_count, count);
            }
        }
        commentNumber.setText(str);
    }

    @OnClick(value = {R.id.title_top_back, R.id.account_subscribe, R.id.comment_layout_write_comment, R.id.comment_layout_number, R.id.comment_layout_doup, R.id.comment_layout_share})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.title_top_back:
                finish();
                break;
            case R.id.account_subscribe:
                //TODO 关注、取消关注
                if (null != newsItem) {
                    if (null != UserManager.getInstance().getUser()) {
                        setResult(RESULT_OK);
                        toAttentionClick(newsItem.getFollowedStatus());
                    } else {
                        toLogin();
                    }
                }
                break;
            case R.id.comment_layout_write_comment:
                String newid = "" + newsItem.getNewsDetailId();
                showCommentDialog(newid,newsItem.getNewsDetailTitle() ,null, 0);  //0代表新闻评论
                setResult(RESULT_OK);
                break;
            case R.id.comment_layout_number:
                if (newsItem.getNewsDetailCommentCount() != 0) {
                    Intent intent = new Intent(this, CommentActivity.class);
                    String id = "" + newsItem.getNewsDetailId();
                    intent.putExtra(EX_ID, id);
                    intent.putExtra(EX_TYPE_NEWS, Constances.REQUEST_COMMENT_TYPE_NEWS);
                    intent.putExtra(EX_COMMENT_TYPE, 0);
                    startActivityForResult(intent, REQUEST_COMMENT_CODE);
                    setResult(RESULT_OK);
                }
                break;
            case R.id.comment_layout_doup:
                newsDoUp();
                break;
            case R.id.comment_layout_share:
                if (!TextUtils.isEmpty(fNews.getShareURL())) {
                    this.setNewsId(fNews.getNewsId());
                    showShareFragment(fNews, new ShareFragment.OnShareFragmentClickListener() {
                        @Override
                        public void onClick(Pair<String, String> pair) {

                        }
                    });
                } else {
                    toast(R.string.share_data_wrong);
                }
                break;
        }
    }

    /**
     * 处理 关注或取消关注
     *
     * @param isAttention
     */
    private void toAttentionClick(int isAttention) {
        if (isAttention == 1) {
            toUnAttentionAccount("" + newsItem.getFollowedId(), new OnAttentionListener() {
                @Override
                public void OnAttention(boolean isSuccess, long attentionedUserNums) {

                }

                @Override
                public void OnUnAttention(boolean isSuccess, long attentionedUserNums) {
                    newsItem.setFollowedStatus(0);
                    accountSubscribe.setImageDrawable(getResources().getDrawable(R.mipmap.icon_subscribe));
                }
            });
        } else {
            toAttentionAccount("" + newsItem.getFollowedId(), new OnAttentionListener() {
                @Override
                public void OnAttention(boolean isSuccess, long attentionedUserNums) {
                    newsItem.setFollowedStatus(1);
                    accountSubscribe.setImageDrawable(getResources().getDrawable(R.mipmap.icon_subscribed));
                }

                @Override
                public void OnUnAttention(boolean isSuccess, long attentionedUserNums) {

                }
            });
        }
    }

    /**
     * 点赞、取消点赞请求
     */
    private void newsDoUp() {
        final String newId = "" + newsItem.getNewsDetailId();
        if (UserManager.isLoginS()) {

            commentDoup.setDrawableEnlarge();
            ParamsEditor pe = new ParamsEditor();
//        HashMap<String, Object> param = new HashMap<>();
            pe.put("dynamicId", newId);
            pe.put("fType", 3);//1 主播 2报料 3新闻 4 直播 5视频
//        pe.put("token", UserManager.getInstance().getToken());
            pe.put("userId", UserManager.getInstance().getUser().getUserId());

            NetUtils.getNetAdapter().doUpForDynamics(getOwnerName(), pe.getEncryptedParams(UserManager.getInstance().getToken()), new AbsNetCallBack<SingleResult>(SingleResult.class) {
                @Override
                public void onSuc(SingleResult singleResult) {
                    if (singleResult.isSuccess()) {
                        if (null != newsItem) {
                            if (newsItem.isNewsDetailAttitudesStatus()) {
                                newsItem.setNewsDetailAttitudesStatus(!newsItem.isNewsDetailAttitudesStatus());
                                newsItem.setNewsDetailAttitudesCount(newsItem.getNewsDetailAttitudesCount() - 1);
                            } else {
                                newsItem.setNewsDetailAttitudesStatus(!newsItem.isNewsDetailAttitudesStatus());
                                newsItem.setNewsDetailAttitudesCount(newsItem.getNewsDetailAttitudesCount() + 1);
                            }

                            if (newsItem.isNewsDetailAttitudesStatus()) {
                                if (UserManager.isLoginS()) {
                                    StatisticsMainInit.thumbsUpLog(UserManager.getInstance().getUser().getPhoneNumber(),String.valueOf(newsItem.getNewsDetailId()),
                                            newsItem.getNewsDetailTitle(),1);
                                }else{
                                    StatisticsMainInit.thumbsUpLog("", String.valueOf(newsItem.getNewsDetailId()),
                                            newsItem.getNewsDetailTitle(),1);
                                }
                                Drawable drawable = AccountNewsDetailActivity.this.getResources().getDrawable(R.mipmap.icon_compere_btn_press);
                                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                                commentDoup.setDrawables(drawable, null, null, null);
                                commentDoup.setTextColor(AccountNewsDetailActivity.this.getResources().getColor(R.color.colorTxRedMain_));
                            } else {
                                if (UserManager.isLoginS()) {
                                    StatisticsMainInit.thumbsUpLog(UserManager.getInstance().getUser().getPhoneNumber(),String.valueOf(newsItem.getNewsDetailId()),
                                            newsItem.getNewsDetailTitle(),2);
                                }else{
                                    StatisticsMainInit.thumbsUpLog("", String.valueOf(newsItem.getNewsDetailId()),
                                            newsItem.getNewsDetailTitle(),2);
                                }
                                Drawable drawable = AccountNewsDetailActivity.this.getResources().getDrawable(R.mipmap.icon_compere_btn_normal);
                                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                                commentDoup.setDrawables(drawable, null, null, null);
                                commentDoup.setTextColor(AccountNewsDetailActivity.this.getResources().getColor(R.color.colorOpinionSelectNo));
                            }
                            commentDoup.setText("" + newsItem.getNewsDetailAttitudesCount());
                            if (newsItem.isNewsDetailAttitudesStatus()) {
                                addInvitation(Constances.ADD_INTEGRAL_DOUP, false);
                            }
                        }
                        setResult(RESULT_OK);
                    }
                }

                @Override
                public void onError(Throwable ex, String errorMsg, int netCode) {
                    super.onError(ex, errorMsg, netCode);
                }
            });

        } else {
            toLogin();
        }
    }

    @Override
    protected void initVideoPlayer(@NonNull BasePlayerView player, VideoInfo info, boolean isLiving) {
        super.initVideoPlayer(player, info, false);
        player.setIsTouchWiget(false);
        setSampleVideoListener(new SampleListener() {
            @Override
            public void onPrepared(String url, Object... objects) {
                super.onPrepared(url, objects);
                JLog.e("aasa   in prepare");

                if (!isAutoRotation()) {
                    setAutoRotation(true);
                }
            }

            @Override
            public void onClickStop(String url, Object... objects) {
                super.onClickStop(url, objects);
                JLog.e("aasa   in click stop");
            }

            @Override
            public void onAutoComplete(String url, Object... objects) {
                super.onAutoComplete(url, objects);
                JLog.e("aasa   in auto complete");
            }

            @Override
            public void onPlayError(String url, Object... objects) {
                super.onPlayError(url, objects);
                JLog.e("aasa   in error");
            }

            @Override
            public void onClickStartIcon(String url, Object... objects) {
                super.onClickStartIcon(url, objects);
                JLog.e("aasa   in click start icon");
            }

            @Override
            public void onClickResume(String url, Object... objects) {
                super.onClickResume(url, objects);
                JLog.e("aasa   in clickResume");

                if (!isAutoRotation()) {
                    setAutoRotation(true);
                }
            }
        });
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
//        if (videoPlayer != null && isVideoType) {
//            videoPlayer.onConfigurationChanged(this, newConfig, null);
//        }
        if (webView != null) {
            webView.reload();
        }
        videoPlayer.setFocusable(true);
        videoPlayer.setFocusableInTouchMode(true);
        videoPlayer.requestFocus();
    }

    @Override
    public void onNetPromptCallBacked(boolean isContinue) {
        if (isContinue) {
//            StandardGSYVideoPlayer player = getVideoPlayer();
            if (videoPlayer != null) {
                videoPlayer.startPlayLogic();
            }
        }
    }

    @Override
    protected void onCommentGetListSuc(int count, List<FComment> fProgrammes) {
        if (indexNumber >= count || count <= capacity) {
            commentCount = count;
            refreshBottomCommentShowing(count);
        }

    }

    @Override
    protected void onCommentSendSuc(int mode) {
        super.onCommentSendSuc(mode);
        getCommentNews("" + newsItem.getNewsDetailId(), Constances.REQUEST_COMMENT_TYPE_NEWS, capacity, indexNumber);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == CODE_REQUEST_LOGIN) {
                getDetailData();
            } else if (requestCode == REQUEST_COMMENT_CODE) {
                getCommentNews("" + newsItem.getNewsDetailId(), Constances.REQUEST_COMMENT_TYPE_NEWS, capacity, indexNumber);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != videoPlayer) {
            videoPlayer.onVideoPause();
            videoPlayer = null;
        }
    }
}
